//
//  HomeVC.m
//  YelenaKit
//
//  Created by sino on 2019/1/4.
//  Copyright © 2019 sino. All rights reserved.
//

#import "HomeVC.h"

@interface DemoItem : NSObject
@property (nonatomic,strong) NSString *name;
@property (nonatomic,strong) NSString *desc;
-(instancetype)initWithName:(NSString*)name desc:(NSString*)desc;
@end

@implementation DemoItem

-(instancetype)initWithName:(NSString*)name desc:(NSString*)desc {
    if (self = [super init]) {
        self.name = name;
        self.desc = desc;
    }
    return self;
}
@end

@interface HomeVC ()
@property (nonatomic,strong) NSMutableArray *data;
@end

@implementation HomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"YLKit示例";
    self.navigationController.navigationBar.translucent = NO;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"democell"];
    [self addDemo];
}

-(void)addDemo {
    
    self.data = [[NSMutableArray alloc]init];
    
    [self.data addObject:[[DemoItem alloc]initWithName:@"YLViewVC" desc:@"YLView 视图"]];
    
    [self.data addObject:[[DemoItem alloc]initWithName:@"YLLabelVC" desc:@"YLLabel 标签"]];
    [self.data addObject:[[DemoItem alloc]initWithName:@"YLButtonVC" desc:@"YLButton 按钮"]];
    [self.data addObject:[[DemoItem alloc]initWithName:@"YLImageViewVC" desc:@"YLImageView 图片框"]];
    
    [self.data addObject:[[DemoItem alloc]initWithName:@"YLTextFieldVC" desc:@"YLTextField 输入框"]];
    [self.data addObject:[[DemoItem alloc]initWithName:@"YLAlertVC" desc:@"YLAlert 警告框"]];

    [self.tableView reloadData];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"democell" forIndexPath:indexPath];
    cell.textLabel.text = ((DemoItem*)self.data[indexPath.row]).desc;
    cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *name = ((DemoItem*)self.data[indexPath.row]).name;
    Class cls = NSClassFromString(name);
    UIViewController *vc = [[cls alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
@end
